package velox.jcr.mapper.loader;

import java.util.ArrayList;
import java.util.List;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;

import velox.jcr.mapper.CachingLoader;
import velox.jcr.mapper.UnitOfWorkHolder;

public class ChildrenLoader extends CachingLoader<List<String>> {

	@Override
	public List<String> doLoad(String uuid) throws RepositoryException {
		List<String> dest = new ArrayList<String>();
		NodeIterator ni = UnitOfWorkHolder.get().getMapperManager().getSession().getNodeByUUID(uuid).getNodes();
		while (ni.hasNext()) {
			Node n = ni.nextNode();
			dest.add(n.getUUID());
		}
		return dest;
	}
}
